<%--
  Created by IntelliJ IDEA.
  User: 步步为莹
  Date: 2019/9/17
  Time: 9:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Beyond车辆管理平台</title>
    <link rel="stylesheet" href="../../static/css/style.css">
    <link rel="stylesheet" href="../../static/css/jquery.wysiwyg.old-school.css">
    
    <!-- jQuery AND jQueryUI -->
    <script type="text/javascript" src="../../static/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../static/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../../static/js/min.js"></script>
    <!--<script type="text/javascript" src="js/index.js"></script>-->
</head>
<body>
<script type="text/javascript" src="../../static/js/main.js"></script>
<link rel="stylesheet" href="../../static/css/style2.css">
<div id="content" class="white">
    <h1><img src="../../static/images/users1.png" alt="">车辆折旧</h1>
    <div class="bloc">
        <div class="title">折旧车辆列表</div>
        <div class="content">
            <table>
                <thead>
                <tr>
                    <th><input type="checkbox" id="selectALL" onclick="selectAll(this)">全选</th>
                    <th>车牌号</th>
                    <th>车辆折旧价格(万)</th>
                    <th>经办人</th>
                    <th>折旧时间</th>
                    <th>备注</th>
                </tr>
                </thead>
                <tbody id="listvehicleRepair">
                
                </tbody>
            </table>
        </div>
    </div>
</div>
<div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>
<script type="text/javascript">

    $.ajax({
        url:"<%=request.getContextPath()%>/VehicleDeprectionServlet",
        type:"GET",
        data:"opr=listVehicleDeprection",
        dataType:"json",
        success:function (result) {
            console.log(result);
            var stuUser="";
            
            $.each(result[0],function (index,ele) {
                stuUser+="<tr>";
                stuUser+="<td><input type='checkbox' class='VehicleProcurementId'>" +
                    "<input type='hidden' value='"+ele.id+"'> </td>"
                stuUser+="<td>"+getforeignkey(result[1],ele.vehicle_id)+"</td>";
                stuUser+="<td>"+ele.deprecition_Price+"</td>";
                stuUser+="<td>"+ele.deprecitionBy+"</td>";
                stuUser+="<td>"+ele.deprecition_date+"</td>";
                stuUser+="<td>"+ele.remark+"</td>";
                stuUser+="<td><a href='javascript:;' title='修改' onclick='update(this)'>\n" +
                    "<img src='../../static/images/edit.png'></a>\n" +
                    "<a href='javascript:;' title='删除' onclick='del(this)'>\n" +
                    "<img src='../../static/images/delete.png'></a></td>";
                stuUser+="</tr>";
            });
            $("tbody#listvehicleRepair").append(stuUser);
        }

    });

    //其他复选框取消选中时全选取消
    function checkFalse(obj){
        if(!$(this).is(":checked")){
            $("#selectALL").prop("checked",false);
        }
    }
    
    //全选
    function selectAll(obj){
        //prop() 方法设置或返回被选元素的属性和值
        if($(obj).is(':checked')){
            $(":checkbox").prop("checked",true);
        }else {
            $(":checkbox").prop("checked",false);
        }
    };

    //删除购买记录
    function  del(obj) {
        var userId=$(obj).parent().siblings("td").children("[type='hidden']").val();
        var confirm=window.confirm("确定删除吗？")
        if (confirm===true){
            $.ajax({
                url:"<%=request.getContextPath()%>/VehicleProcurementServlet",
                data:"Id="+userId+"&opr=deletevehicleProcurement",
                dataType:"text",
                type:"GET",
                success:function (result) {
                    console.log(result)
                    if (result=='true'){
                        alert("删除成功！");
                    }else {
                        alert("删除失败！");
                    }
                }
            })
        }
    }

    /**
     * 获得外键的值
     * @param array
     * @param id
     * @param type
     * @returns {*}
     */
    function getforeignkey(array,id) {
        var value;
        for (var i=0;i<array.length;i++){
            if (array[i].id == id){
                value=array[i].licenseNumber;
                break;
            }
        }
        return value;
    }
</script>

</body>
</html>
